﻿using System;
using System.Collections.Generic;

namespace 链式编程
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Db person = new Db { Name = "Tom" }
              .Run()
              .Sing()
              .Swim();


            WebBuilder builder = new WebBuilder();
            
            builder
                .AddControllers(new MyController())
                .AddControllers(new MyController2())
                .AddServices(new MyService());

            Console.ReadKey();
        }
    }

    public class Db
    {
        public string Name { get; set; }
        public Db Run()
        {
            Console.WriteLine("Run");
            return this;
        }
        public Db Swim()
        {
            Console.WriteLine("Swim");
            return this;
        }
        public Db Sing()
        {
            Console.WriteLine("Sing");
            return this;
        }
    }


    public interface IService
    {

    }

    public interface IController
    {

    }

    public class MyService : IService
    {

    }

    public class MyController : IController
    {

    }

    public class MyController2 : IController
    {

    }


    public class WebBuilder
    {

    }


    public class Config
    {

    }

    public static class WebBuilderExtensions
    {

        public static List<IController> controllers = new List<IController>();
        public static List<IService> services = new List<IService>();


        public static WebBuilder AddServices(this WebBuilder builder,IService service)
        {
            services.Add(service);

            return builder;
        }

        public static WebBuilder AddControllers(this WebBuilder builder, IController controller)
        {
            controllers.Add(controller);
            return builder;
        }

        public static WebBuilder Config(this WebBuilder builder,Config config)
        {
            return builder;
        }

        public static WebBuilder Build(this WebBuilder builder)
        {
            return builder;
        }

    }



}
